from machine import Pin, PWM
import time

# pwm0 = PWM(Pin(12)) # 定义引脚
# freq = pwm0.freq() # 定义 Hz
# pwm0.freq(1000) # 定义 频率

# duty = pwm0.duty() # 获取值
# print(duty)
# pwm0.duty(256) # 设置值

led2 = PWM(Pin(12))
led2.freq(1000)

while True:
    for i in range(0, 1024):
        led2.duty(i)
        time.sleep_ms(1)
    time.sleep_ms(200)
    for i in range(1023, -1, -1):
        led2.duty(i)
        time.sleep_ms(1)
    time.sleep_ms(200)